package com.yh.doing.interpret_pattern.demo2;

/**
 * @program: design-patterns
 * @description:
 * @author: yangh0597@163.com
 * @date: 2022-11-27 12:04
 * @problem:
 **/
public class OperatorUtil {

    public static boolean isOperator(String symbol) {
        return (symbol.equals("+") || symbol.equals("-") || symbol.equals("*") || symbol.equals("/"));
    }

    public static NonTerminalExpression getTerminalExpression(IExpression left, IExpression right, String symbol) {
        switch (symbol) {
            case "+":
                return new AddNonTerminalExpression(left, right);
            case "-":
                return new SubNonTerminalExpression(left, right);
            case "*":
                return new MultiNonTerminalExpression(left, right);
            case "/":
                return new DivNonTerminalExpression(left, right);

        }

        return null;

    }
}
